<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Escape a string for use in an LDAP filter or DN</title>
 </head>
 <body class="docs"><div id="layout">
  <div id="layout-content"><div id="function.ldap-escape" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">ldap_escape</h1>
  <p class="verinfo">(PHP 5 &gt;= 5.6.0, PHP 7)</p><p class="refpurpose"><span class="refname">ldap_escape</span> &mdash; <span class="dc-title">Escape a string for use in an LDAP filter or DN</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-function.ldap-escape-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>ldap_escape</strong></span>
    ( <span class="methodparam"><span class="type">string</span> <code class="parameter">$value</code></span>
   [, <span class="methodparam"><span class="type">string</span> <code class="parameter">$ignore</code><span class="initializer"> = &quot;&quot;</span></span>
   [, <span class="methodparam"><span class="type">int</span> <code class="parameter">$flags</code><span class="initializer"> = 0</span></span>
  ]] ) : <span class="type">string</span></div>

  <p class="para rdfs-comment">
   Escapes <code class="parameter">value</code> for use in the context implied by
   <code class="parameter">flags</code>.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.ldap-escape-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>

    
     <dt>
<code class="parameter">value</code></dt>

     <dd>

      <p class="para">
       The value to escape.
      </p>
     </dd>

    
    
     <dt>
<code class="parameter">ignore</code></dt>

     <dd>

      <p class="para">
       Characters to ignore when escaping.
      </p>
     </dd>

    
    
     <dt>
<code class="parameter">flags</code></dt>

     <dd>

      <p class="para">
       The context the escaped string will be used in:
       <strong><code>LDAP_ESCAPE_FILTER</code></strong> for filters to be used with
       <span class="function"><a href="ldap_search.html" class="function">ldap_search()</a></span>, or
       <strong><code>LDAP_ESCAPE_DN</code></strong> for DNs.
       If neither flag is passed, all chars are escaped.
      </p>
     </dd>

    
   </dl>

  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.ldap-escape-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   Returns the escaped string.
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.ldap-escape-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   When building an LDAP filter, you should use ldap_escape with LDAP_ESCAPE_FILTER flag.
   <div class="example" id="example-5396">
    <p><strong>Example #1 Searching for an email address</strong></p>
<div class="example-contents">
<div class="phpcode"><pre><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #FF8000">//&nbsp;$ds&nbsp;is&nbsp;a&nbsp;valid&nbsp;link&nbsp;identifier&nbsp;for&nbsp;a&nbsp;directory&nbsp;server<br /><br />//&nbsp;$mail&nbsp;is&nbsp;an&nbsp;email&nbsp;address&nbsp;provided&nbsp;by&nbsp;the&nbsp;user&nbsp;in&nbsp;a&nbsp;form<br /><br /></span><span style="color: #0000BB">$base&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">"o=My&nbsp;Company,&nbsp;c=US"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$filter&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">"(mail="</span><span style="color: #007700">.</span><span style="color: #0000BB">ldap_escape</span><span style="color: #007700">(</span><span style="color: #0000BB">$mail</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">""</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">LDAP_ESCAPE_FILTER</span><span style="color: #007700">).</span><span style="color: #DD0000">")"</span><span style="color: #007700">;<br /><br /></span><span style="color: #0000BB">$sr&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">ldap_search</span><span style="color: #007700">(</span><span style="color: #0000BB">$ds</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$base</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$filter</span><span style="color: #007700">,&nbsp;array(</span><span style="color: #DD0000">"sn"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"givenname"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"mail"</span><span style="color: #007700">));<br /><br /></span><span style="color: #0000BB">$info&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">ldap_get_entries</span><span style="color: #007700">(</span><span style="color: #0000BB">$ds</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$sr</span><span style="color: #007700">);<br /><br />echo&nbsp;</span><span style="color: #0000BB">$info</span><span style="color: #007700">[</span><span style="color: #DD0000">"count"</span><span style="color: #007700">].</span><span style="color: #DD0000">"&nbsp;entries&nbsp;returned\n"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</pre></div>
    </div>

   </div>
  </p>
 </div>

</div></div></div></body></html>